﻿<UserControl x:Class="CannedBytes.CommandLineGui.UI.GuiDocumentPage" x:ClassModifier="internal"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:v="clr-namespace:CannedBytes.CommandLineGui.Model.Validation"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Image Name="ValidationImage" HorizontalAlignment="Right"
               Validation.ValidationAdornerSiteFor="{Binding ElementName=ToolLocation}"
               Source="/CannedBytes.CommandLineGui;component/Resources/Alert.png"
               Style="{StaticResource ValidationImage}">
        </Image>

        <TextBox Name="ToolLocation" HorizontalAlignment="Stretch" Grid.Column="1"
                 TextChanged="ToolLocation_TextChanged"
                 ToolTip="The full path to the Tool executable file. Use of environment variables is allowed.">
            <TextBox.Text>
                <Binding Path="ToolInfo.ToolExecutablePath" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                    <Binding.ValidationRules>
                        <v:FileExistsValiadtionRule ValidatesOnTargetUpdated="True" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <StackPanel Grid.Column="2"  Orientation="Horizontal">
            <Button Name="BrowseLocation" Click="BrowseLocation_Click" ToolTip="Browse to select the Tool executable file.">
                <Image Source="/CannedBytes.CommandLineGui;component/Resources/Export File.png" />
            </Button>
            <Button Name="RestoreLocation" Click="RestoreLocation_Click" ToolTip="Restore Tool executable file path."
                    Visibility="{Binding ToolInfo.IsToolExecutablePathOverridden, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                <Image Source="/CannedBytes.CommandLineGui;component/Resources/Import Mail.png" />
            </Button>
        </StackPanel>

        <!-- this displays the tools control -->
        <ContentPresenter Grid.ColumnSpan="3" Grid.Row="1"
                          Content="{Binding Path=ToolBindingModel, Mode=OneTime}"
                          ContentTemplateSelector="{StaticResource ControlTemplateSelector}" />
    </Grid>
</UserControl>